<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/admincontent.jsp" %>


<div id="location">当前位置：系统信息管理 > 角色管理</div>
<div id="sy_search" class=" f0f0f0" style="display: inline-block">
    <form id="advanceQueryParam">
        <div style="background-color: #f0f0f0">
            <div class="clearfix more_query_area">
                <div class="query_area_body clearfix">
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">角色名称:</div>
                            <div class="content">
                                <div><input type="text" name="rname"/></div>
                            </div>
                        </div>
                    </div>
<%--                    <div class="query_area_footer clearfix">
                        <div class="query_btns clearfix">
                            <div class="query_btn left blue" id="searchbtn">
                                <span class="label">查询</span>
                            </div>
                            <div class="query_btn left gray" id="searchreset">
                                <span class="label">重置</span>
                            </div>
                        </div>
                    </div>--%>
                    <div class="record_item">
                        <div class="toolbars">
                            <a id="searchbtn" >
                                <em class="ico16 search_16"></em>
                                <span class="menu_span" title="查询">查询</span>
                            </a>
                            <a id="searchreset">
                                <em class="ico16 refresh_16"></em>
                                <span class="menu_span" title="重置">重置</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
<%--    <a width="60" id="combineQuery" class="font_size12 common_button combinedQuery">查询</a>--%>
</div>
<div id="Content" class="bg-content">
    <%--   <div class="clearfix common_toolbar_box">--%>
    <div class="toolbars" style="height:30px;white-space:nowrap;width:auto;margin-left: 20px;" totalwidth="314">
        <a id="role_add">
            <em class="ico16 add_new"></em>
            <span class="menu_span">添加</span>
        </a>
        <a id="role_edit">
            <em class="ico16 editor_16"></em>
            <span class="menu_span">编辑</span>
        </a>
        <a id="role_del">
            <em class="ico16 del_16"></em>
            <span class="menu_span">删除</span>
        </a>
        <a id="role_right">
            <em class="ico16 authorize_16"></em>
            <span class="menu_span">权限分配</span>
        </a>
    </div>
    <%--    </div>--%>
</div>
<div style="overflow:hidden;">
    <div id="div_table" style="bottom: 0px">
        <table class="layui-hide" id="table" lay-filter="rolesTable"></table>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        let reload;
        layui.use('table', () => {
            let table = layui.table;
            table.render({
                id: 'table'
                , elem: '#table'
                , height: 'full'
                , url: '/SysAdmin/getRolesLayuiJson' //数据接口
                , title: '用户表'
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left', width: '5%'}
                    , {type: 'numbers', title: '序号', width: '10%', sort: true}
                    , {field: 'rname', title: '角色名称', width: '30%', sort: true}
                    , {field: 'rtype', title: '角色类型', width: '30%', sort: true}
                    , {field: 'remark', title: '角色描述', width: '25%', sort: true}
                ]]
            });
            reload = () => {
                table.reload('table');
            }
            document.tablereload = reload;
            $("#searchbtn").on('click', () => {
                table.reload('table', {
                    where: {
                        rname: $("input[name='rname']").val(),
                    }, page: {
                        curr: 1
                    }
                    , done: (res, curr, count)=>{
                        tableresize(diff, false)
                    }
                })
            })
        });
        //添加角色
        $('#role_add').click(function () {
            openLayer('添加角色', '/SysAdmin/roleadd', '700px', '90%');
            reload();
        });

        //修改角色
        $('#role_edit').click(
            function () {
                LEditInfo('编辑角色', '/SysAdmin/roleedit?_x=2015', '700px', '90%');
            }
        );

        //删除角色
        $('#role_del').click(function () {
            LDeleteInfo('/SysAdmin/DelRoleAction', (d)=>{
                layer.msg(d.Message, {icon: 1, time: 2000})
                reload()
            }, ()=>{
                layer.msg(d.Message,  {icon:1, time: 2000})
            })
        });

        //权限分配
        $('#role_right').click(function () {
            let chosendata = layui.table.checkStatus('table').data;
            if (chosendata.length < 1) {
                layer.msg('请选择一条信息', {icon: 7, time: 2000});
            } else if (chosendata.length > 1) {
                layer.msg('只能选择一条信息', {icon: 7, time: 2000});
            } else {
                openLayer('权限分配', '/SysAdmin/roleright?_x=2015' + '&id=' + chosendata[0].id, '700px', '90%');
            }
            // EditInfo('权限分配', '/SysAdmin/roleright?_x=2015', '98%', '98%');
        });


        function tableresize(diff, resizeout=true) {
            let height3 = $("#div_table").height();
            let height4 = $(".layui-table-body.layui-table-main").height();
            let height5 = $(".layui-form.layui-border-box.layui-table-view").height();


            if (resizeout) {
                $("#div_table").height(height3 - diff);
            }
            $(".layui-table-body.layui-table-main").height(height4 - diff);
            $(".layui-form.layui-border-box.layui-table-view").height(height5 - diff);
        }
        let diff;
        let origin = {};
        $("#combineQuery").on('click', (e) => {


            let style = $("#advanceQueryParam")[0].style;
            if (style.display === 'block') {
                style.display = 'none';
                diff = -origin.diff;
            } else {
                style.display = 'block';
                if (!origin.diff) {
                    origin.diff = document.documentElement.scrollHeight - document.documentElement.clientHeight;
                }
                diff = origin.diff;
            }
            tableresize(diff);
        });
        $("#searchreset").on('click', (e) => {
            document.getElementById("advanceQueryParam").reset();
            $("input[name='deptcode']").val("")
        });
    });


</script>
</body>
</html>